package com.ymk;

import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson.JSON;
import com.ymk.base.cmd.ACmd;
import com.ymk.base.cmd.CmdSign;
import com.ymk.base.exception.MallException;
import com.ymk.base.utlis.Aes;
import com.ymk.base.utlis.ParamsBuilder;
import com.ymk.bo.user.SopUserBO;
import com.ymk.core.code.cmd.SessionCmdCode;
import com.ymk.core.code.cmd.UserCmdCode;
import com.ymk.core.constants.SysConstants;
import com.ymk.core.enums.sop.SopUserStatusEnum;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Objects;

@Service
public class SopSessionGetCmd extends ACmd {

    @Override
    public CmdSign executeSop(HttpServletRequest request, CmdSign sign) throws Exception {
        CmdSign respSign = new CmdSign(sign);

        String dbSopUserBOStr = this.redisTemplate.opsForValue().get(SysConstants.REDIS_KEY_JWT + sign.getToken());
        if (StringUtils.isBlank(dbSopUserBOStr)){
            throw new MallException(410,"会话过期");
        }

        respSign.setSource(super.getSource(JSON.parseObject(dbSopUserBOStr,SopUserBO.class)));
        return respSign;
    }

    @Override
    public String getCmdCode() {
        return SessionCmdCode.SOP_MEMBER_GET;
    }

    @Autowired
    private RedisTemplate<String, String> redisTemplate;
}
